import { defineStore } from 'pinia';
import { fetchBooks, books } from '@/apis/getBooks_by_tags.js';

export const useBookStore = defineStore('book', {
  state: () => ({
    books: [], // books 不需要是 ref
  }),
  actions: {
    addBook(book) {
      this.books.push(book);
    },
    async fetchBooks() {
      await fetchBooks('all');
      this.books = books.value; // 确保使用 books.value 获取最新数据
    },
    updateBooks(newBooks) {
      this.books = newBooks;
    }
  },
});